package practice;

import java.util.*;

public class Day22 {
    //削减整数
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for(int i = 0; i < T; i++) {
            int x = in.nextInt();
            int count = 1;
            x--;
            int a = 1;
            while(x > 0) {
                if(x % (2*a) == 0) {
                    //走2a的道路
                    x -= 2*a;
                    a *= 2;
                }else {
                    //走a的道路
                    x -= a;
                }
                count++;
            }
            System.out.println(count);
        }
    }
    //最长上升子序列
    public int LIS (int[] a) {
        int n = a.length;
        if(n == 0) {
            return 0;
        }
        int[] hash = new int[n+1];
        int i = 0;
        for(int x : a) {
            if(i == 0 || x > hash[i]) {
                hash[++i] = x;
            }else {
                //二分查找
                int l = 1;
                int r = i;
                int mid = 0;
                while(l < r) {
                    mid = l + (r - l) / 2;
                    if(x > hash[mid]) {
                        l = mid + 1;
                    }else {
                        r = mid;
                    }
                }
                hash[l] = x;
            }
        }
        return i;
    }
    //最长子序列
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        String s1 = in.next();
        String s2 = in.next();
        int[][] dp = new int[n+1][m+1];
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= m; j++) {
                if(s1.charAt(i-1) == s2.charAt(j-1)) {
                    dp[i][j] = dp[i-1][j-1]+1;
                }else {
                    dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        System.out.println(dp[n][m]);
    }

    //最小覆盖子串
    public String minWindow(String s, String t) {
        Map<Character,Integer> map = new HashMap<>();
        for(int i = 0; i < t.length(); i++) {
            char ch = t.charAt(i);
            map.put(ch,map.getOrDefault(ch,0)+1);
        }
        int left = 0;
        int right = 0;
        int min = Integer.MAX_VALUE;
        int count = 0;
        int i = -1;
        int j = -1;
        Map<Character,Integer> flag = new HashMap<>();
        while(right < s.length()) {
            char ch = s.charAt(right);
            flag.put(ch,flag.getOrDefault(ch,0) + 1);
            if(map.getOrDefault(ch,0) >= flag.getOrDefault(ch,0)) {
                count++;
            }
            //出队列
            while(count >= t.length()) {
                if(right-left+1 < min) {
                    min = right-left+1;
                    i = left;
                    j = right;
                }
                ch = s.charAt(left);
                flag.put(ch,flag.getOrDefault(ch,0) - 1);
                if(map.getOrDefault(ch,0) > flag.getOrDefault(ch,0)) {
                    count--;
                }
                left++;
            }
            right++;
        }
        if(i ==-1 && j == -1) {
            return "";
        }
        return s.substring(i,j+1);
    }

    //串连所有字串
    public List<Integer> findSubstring(String s, String[] words) {
        Map<String,Integer> map = new HashMap<>();
        int n = words.length;
        int m = words[0].length();
        int len = s.length();;
        for(int i = 0; i < n; i++) {
            map.put(words[i],map.getOrDefault(words[i],0)+1);
        }
        List<Integer> ret = new LinkedList<>();
        int num = n*m;
        for(int i = 0; i < m; i++) {
            int left = i;
            int right = i;
            int count = 0;
            Map<String,Integer> flag = new HashMap<>();
            while(right + m <= len) {
                while(right-left+1 > n*m) {
                    String tmp = s.substring(left,left+m);
                    flag.put(tmp,flag.getOrDefault(tmp,0) - 1);
                    if(map.getOrDefault(tmp,0) > flag.getOrDefault(tmp,0)) {
                        count--;
                    }
                    left += m;
                }
                String str = s.substring(right,right+m);
                flag.put(str,flag.getOrDefault(str,0) + 1);
                System.out.println("left: " + left + "right: " +right);
                System.out.println(str);
                System.out.println(count);
                if(flag.getOrDefault(str,0) <= map.getOrDefault(str,0)) {
                    count++;
                }
                System.out.println(count);
                if(count == n) {
                    ret.add(left);
                }
                right += m;
            }
        }
        return ret;
    }

    //春游：情况要考虑完全
    public static void main4(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for(int i = 0; i < T; i++) {
            long n = in.nextInt();
            long a = in.nextInt();
            long b = in.nextInt();
            long ret = 0;
            if(n < 2) {
                System.out.println(Math.min(a,b));
            }else {
                if(3*a < 2*b) {
                    //选双人
                    ret += (n / 2) * a;
                    if(n % 2 != 0) {
                        ret += Math.min(Math.min(a,b),b-a);
                    }
                }else {
                    //选三人
                    ret += (n / 3) * b;
                    if(n % 3 == 1) {
                        ret += Math.min(Math.min(a,b),2*a-b);
                    }else if(n % 3 == 2){
                        ret += Math.min(Math.min(a,b),3*a-b);
                    }
                }
                System.out.println(ret);
            }
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        int k = in.nextInt();
        int d = in.nextInt();
        //从前i位置挑选j个，最后一个人必选，此时的最大乘积
        int[][] f = new int[n + 1][k + 1];
        //从前i位置挑选j个，最后一个人必选，此时的最小乘积
        int[][] g = new int[n + 1][k + 1];

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= Math.min(k,i); j++) {
                if(j == 1) {
                    f[i][j] = arr[i];
                    g[i][j] = arr[i];
                }else {
                    f[i][j] = Integer.MAX_VALUE;
                    g[i][j] = Integer.MAX_VALUE;
                }
                int prev = Math.max(i-d,j-1);
                while(prev++ < i) {
                    f[i][j] = Math.max(f[i][j], Math.max(f[prev][j-1] * arr[i-1],g[prev][j-1] * arr[i-1]));
                    g[i][j] = Math.min(g[i][j], Math.min(f[prev][j-1] * arr[i-1],g[prev][j-1] * arr[i-1]));
                }

            }
        }
        int max = 0;
        for(int i = 1; i <= k; i++) {
            max = Math.max(max,f[i][k]);
        }
        System.out.println(max);
    }
}
